﻿using System;

namespace NamedBinaryTag
{
	/// <summary>
	/// Factory for Tag creation.
	/// </summary>
	public static class TagFactory
	{
		/// <summary>
		/// Instantiates the Tag with the specified type id.
		/// </summary>
		/// <param name="tagType">The tag id of the Tag to instantiate.</param>
		/// <returns>The instantiated Tag.</returns>
		/// <exception cref="System.ArgumentOutOfRangeException" />
		public static ITag CreateTag(byte tagType)
		{
			ITag tag = null;
			switch (tagType)
			{
				case 0:
					tag = new TagEnd();
					break;
				case 1:
					tag = new TagByte();
					break;
				case 2:
					tag = new TagShort();
					break;
				case 3:
					tag = new TagInt();
					break;
				case 4:
					tag = new TagLong();
					break;
				case 5:
					tag = new TagFloat();
					break;
				case 6:
					tag = new TagDouble();
					break;
				case 7:
					tag = new TagByteArray();
					break;
				case 8:
					tag = new TagString();
					break;
				case 9:
					tag = new TagList();
					break;
				case 10:
					tag = new TagCompound();
					break;
				default:
#if !SILVERLIGHT
					throw new ArgumentOutOfRangeException("tagType", tagType, "Unknow tag type.");
#else
					throw new ArgumentOutOfRangeException("tagType", "Unknow tag type.");
#endif
			}
			return tag;
		}
	}
}
